<template>
  <div>
    <el-container>
      <el-header>
        <span>
          <img src="../assets/logo.png" alt="" />
          <i>后台管理系统</i>
        </span>

        <el-button type="primary" class="el-butt" @click="open"
          >退出登录</el-button
        >
      </el-header>

      <el-container>
        <el-aside
          width="200px"
          :class="{ open: isCollapse == false, close: isCollapse == true }"
        >
          <header class="aaa" @click="isCollapse = !isCollapse">
            <i class="el-icon-s-unfold"></i>
          </header>
          <el-col>
            <el-menu
              class="el-menu-vertical-demo"
              background-color="#000"
              text-color="#fff"
              active-text-color="#ffd04b"
              :collapse="isCollapse"
              router
              :unique-opened="true"
              :default-active="$store.state.active"
              @select="select"
            >
              <el-submenu
                :index="item.id.toString()"
                v-for="(item, index) in menus"
                :key="index"
              >
                <template slot="title">
                  <i :class="icon[index]"></i>
                  <span>{{ item.authName }}</span>
                </template>
                <el-menu-item-group>
                  <el-menu-item
                    :index="ite.path"
                    v-for="(ite, ind) in item.children"
                    :key="ind"
                    >{{ ite.authName }}</el-menu-item
                  >
                </el-menu-item-group>
              </el-submenu>
            </el-menu>
          </el-col>
        </el-aside>
        <el-main>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
import { menus } from '@/api/login.js'
export default {
  data() {
    return {
      isCollapse: false,
      menus: [],
      icon: [
        'el-icon-user-solid',
        'el-icon-s-tools',
        'el-icon-s-goods',
        'el-icon-s-order',
        'el-icon-s-data',
      ],
    }
  },
  mounted() {
    menus().then((res) => {
      // console.log(res.data.data);
      this.menus = res.data.data
    })
  },
  methods: {
    // 退出登录
    open() {
      this.$confirm('你确定要退出登录嘛？, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(() => {
          localStorage.removeItem('token')
          this.$router.push('/')
          this.$message({
            type: 'success',
            message: '退出成功!',
          })
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '取消退出',
          })
        })
    },
    select(e) {
      this.$store.commit('select', e)
      // console.log(e)
    },
  },
  computed: {},
}
</script>

<style scoped lang="scss">
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}
.el-header {
  width: 100%;
  height: 40px;
  background: #000;
  display: flex;
  justify-content: space-between;
  color: #fff;
  text-align: center;
  line-height: 40px;
  span {
    font-size: 26px;
    font-weight: 900;
    display: flex;
    justify-content: space-between;
    color: #fff;
    align-items: center;
    img {
      width: 50px;
      height: 50px;
    }
  }
  .el-butt {
    width: 100px;
    height: 50px;
    margin-top: 5px;
    margin-right: 10px;
  }
}
.el-aside {
  background: #000;
  height: 500px;
  head {
    height: 30px;
    line-height: 30px;
    background: pink;
  }
  .el-col {
    background: #000;
  }
}
.aaa {
  text-align: center;
  color: #fff;
  height: 40px;
  line-height: 40px;
}
.close {
  width: 60px !important;
}
.open {
  width: 200px !important;
}
</style>
